package com.ttb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class ScheduleHandler extends SQLiteOpenHelper{
	// database version
	public static final int DATABASE_VERSION = 1;
	// database name
	public static final String DATABASE_NAME = "smshelper";
	// contact table name
	public static final String SCHEDULE_TABLE = "schedule_list";
	// contact columns name
	public static final String KEY_ID = BaseColumns._ID;
	public static final String KEY_PHONE_LIST = "list_phone_number";
	public static final String KEY_TRIGGER_TIME = "trigger_time";
	public static final String KEY_INTERVAL = "interval";
	public static final String KEY_MESSAGE = "message";
	public ScheduleHandler(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String createString = "CREATE TABLE " + SCHEDULE_TABLE + "( " + KEY_ID
				+ " INTEGER PRIMARY KEY, " 
				+ KEY_PHONE_LIST + " TEXT,"
				+ KEY_MESSAGE + " TEXT,"
				+ KEY_TRIGGER_TIME + " LONG, " 
				+ KEY_INTERVAL + " TEXT"
				+ ");";
		Log.d("SCHEDULE TABLE CREATE :", createString);
		db.execSQL(createString);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(ScheduleHandler.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + SCHEDULE_TABLE);
		onCreate(db);
		
	}
	
}
